<% layout('/layouts/default.html', {title: '文件分发管理', libs: ['dataGrid']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-notebook"></i> ${text('待还文列表')}

            </div>
            <div class="box-tools pull-left" style="margin-left: 50px;">
                <a href="#" style="color:red" class="btn btn-default"  onclick="selectUnit(3)"  id="song" title="${text('送文单位')}"><i class=" "></i> ${text('送文')}</a>
                <a href="#" class="btn btn-default"  onclick="selectUnit(2)" id="ling" title="${text('领文单位')}"><i class=" "></i> ${text('领文')}</a>
            </div>
            <div class="box-tools pull-right">
                <a href="javascript:;" class="btn btn-default" id="return" title="${text('还文')}"><i class="fa fa-mail-reply"></i> ${text('还文')}</a>
                <a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
            </div>
        </div>
        <div class="box-body">
            <#form:form id="searchForm" model="${docDeliverRecord}" action="${ctx}/sd/docDeliverWaitReturn/listData" method="post" class="form-inline hide"
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
            <div class="form-group">
                <label class="control-label">${text('来文自编号')}：</label>
                <div class="control-inline">
                    <#form:input path="docRecv.docSysCode" maxlength="64"  class="form-control width-120"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('文件标题')}：</label>
                <div class="control-inline">
                    <#form:input path="docRecv.docTitle" maxlength="4" class="form-control width-120"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('紧急程度')}：</label>
                <div class="control-inline" style="width: 80px">
                    <#form:select path="docRecv.docEmergLvl"  dictType="recv_doc_emerg_lvl" blankOption="true" class="form-control"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('密级')}：</label>
                <div class="control-inline width-120">
                    <#form:select path="docRecv.secLvl" dictType="recv_sec_lvl" blankOption="true" class="form-control"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('领文单位')}：</label>

                <div class="control-inline width-120">
                    <#form:treeselect id="unit" title="领文单位选择" path="recvUnitCode"
                    url="${ctx}/sd/docDeliverRecord/treeData" class="" allowClear="true" />
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('单位类型')}：</label>

                <div class="control-inline width-120">
                    <#form:select path="deliverType" id="lx" dictType="sd_deliver_send_take" blankOption="true" class="form-control"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('领文人警号')}：</label>
                <div class="control-inline">
                    <#form:input path="takeUserPoliceno" maxlength="64" class="form-control width-120"/>
                </div>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
                <button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
            </div>
        </#form:form>
        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>
</div>
</div>
<% } %>
<script src="${ctxStatic}/common/des.js?${_version}"></script>
<script>
    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {header:'${text("来文自编号")}', name:'docRecv.docSysCode', index:'c.doc_sys_code', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
                    return '<a href="${ctx}/sd/docDeliverWaitReturn/form?id='+row.id+'" class="btnList" data-title="${text("编辑文件分发")}">'+(val||row.id)+'</a>';
                }},
            {header:'${text("文件文号")}', name:'docRecv.docFullNum', index:'c.doc_full_num', width:150, align:"center"},
            {header:'${text("文件分发编号")}', name:'docCopyNo', index:'doc_copy_no', width:150, align:"center"},
            {header:'${text("文件标题")}', name:'docRecv.docTitle', index:'c.doc_title', width:150, align:"center"},
            {header:'${text("紧急程度")}', name:'docRecv.docEmergLvl', index:'c.doc_emerg_lvl', width:150, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('recv_doc_emerg_lvl')}, val, '${text("未知")}', true);
                }},
            {header:'${text("密级")}', name:'docRecv.secLvl', index:'c.sec_lvl', width:80, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('recv_sec_lvl')}, val, '${text("未知")}', true);
                }},
            {header:'${text("领文单位")}', name:'office.officeName', index:'o.office_name', width:150, align:"center"},
           /* {header:'${text("领文单位邮箱")}', name:'office.extend.extendS4', index:'o.extend_s4', width:150, align:"center"},*/
            {header:'${text("单位类型")}', name:'deliverType', index:'a.deliver_type', width:150, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('sd_deliver_send_take')}, val, '${text("未知")}', true);
                }},
            {header:'${text("领文时间")}', name:'takeDate', index:'take_date', width:150, align:"center"},
            {header:'${text("领文人姓名")}', name:'takeUserName', index:'take_user_name', width:150, align:"center"},

            {header:'${text("领文人警号")}', name:'takeUserPoliceno', index:'take_user_policeno', width:150, align:"center"},
            {header:'${text("截止归还日期")}', name:'beforeReturnDate', index:'before_return_date', width:150, align:"center",formatter:function (val,act) {
                         var date=new Date();
                       var t=  date.getTime();
                       var history=new Date(val).getTime();
                       if (t>history) {
                          return "<span style='color: red'>"+val+"</span>"
                       }
                            return val;



                }},
            {header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
                    var actions = [];
                <% if(hasPermi('sd:docDeliverWaitReturn:edit')){ %>
                        actions.push('<a href="${ctx}/sd/docDeliverWaitReturn/form?id='+row.id+'" class="btnList" title="${text("查看")}"><i class="fa fa-search"></i></a>&nbsp;');
                    <% } %>
                    return actions.join('');
                }}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });


    function selectUnit(data){
        $("#lx").val(data).trigger('change');
        page();
    }

    $("#return").click(function () {
        js.layer.open({
            type: 2,
            area: [(js.layer.window.outerWidth-200)+'px',(js.layer.window.outerHeight-200)+'px'],
            title: '${text("文件归还")}',
            resize: false,
            scrollbar: true,
            maxmin:true,
            content: '${ctx}/sd/docDeliverRecord/toDocReturn',
            success: function(layero, index){

            },
            btn: ['<i class="fa fa-check"></i> ${text("归还")}',
                '<i class="fa fa-remove"></i> ${text("关闭")}'],
            btn1: function(index, layero){

                let win = layero.iframeWindow();
                let form = {
                    inputForm: win.$('#inputForm'),
                };
                let rows = win.$('#dataGrid').dataGrid('getRowData');
                //归还文件数组
                if(rows.length === 0){
                    js.layer.msg('归还文件不能为空!', {icon: 5});
                    return false;
                }
                if(win.$('#password').val()===''){
                    js.layer.msg('操作员密码不能为空!', {icon: 5});
                    return false;
                }

                //判断是否为默认用户(连个都为空则证明没有上传图片)
                if (win.$('#userCode').val() === ''
                    &&win.$('#pictureSrc').val() === '') {
                        js.layer.msg('请先提交还文人照片!', {icon: 5});
                        return false;
                }

                //判断 警号,姓名,图片路径是否为空
                if (win.$('#userName').val() === '') {
                    js.layer.msg('还文人姓名不能为空!', {icon: 5});
                    return false;
                }
                if (win.$('#policeNo').val() === '') {
                    js.layer.msg('还文人警号不能为空!', {icon: 5});
                    return false;
                }


                let formData = new FormData;
                let secretKey = '${@Global.getConfig("shiro.loginSubmit.secretKey")}';
                //密码加密传输
                win.$('#password').val( DesUtils.encode(win.$('#password').val(), secretKey));

                //还文
                js.ajaxSubmitForm(form.inputForm, function(data){
                    if(data.result === Global.TRUE){
                        js.showMessage(data.message);
                        js.layer.closeAll();
                        page();
                        return true;
                    }else{
                        js.layer.msg(data.message, {icon: 5});
                        return false;
                    }

                    page();
                }, "json");

                return false;
            }
        });
    });
</script>